﻿/*
 * Crée par SharpDevelop.
 * Utilisateur: ngr
 * Date: 25/02/2015
 * Heure: 14:18
 * 
 * Pour changer ce modèle utiliser Outils | Options | Codage | Editer les en-têtes standards.
 */
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Data.SQLite;

namespace Compta.Core.Classes 
{
	
	/// <summary>
	/// Description of Account.
	/// </summary>
	public class Account
	{
		// PROPRIETES
		public int Id{
			get; set;
		}
		public int Bank_Id{
			get; set;
		}
		public string Bank{
			get; set;
		}
		public string Name{
			get; set;
		}
		public string Devise_Code{
			get; set;
		}
		public string Devise_Label{
			get; set;
		}
		public string Devise_Symbole{
			get; set;
		}
		public string Owner{
			get; set;
		}
		public float BalanceReal
		{
			get; set;
		}
		public float BalanceProjected{
			get; set;
		}	
		public Operation[] Operations
		{
			get{return operations.ToArray();}
		}
		List<Operation> operations;
		
		// Autres variables
		public ComptaCore core ;
		
		
		public Account() 
		{
			operations = new List<Operation>();
		}
		
		public Account(ComptaCore core)
		{
			this.core = core;
			operations = new List<Operation>();
		}
		
		public Account(ComptaCore core, Account acc)
		{
			this.core = core;
			
			
			this.Id = acc.Id;
			this.Bank = acc.Bank;
			this.Bank_Id = acc.Bank_Id;
			this.BalanceProjected = acc.BalanceProjected;
			this.BalanceReal = acc.BalanceReal;
			this.Devise_Code = acc.Devise_Code;
			this.Devise_Label = acc.Devise_Label;
			this.Devise_Symbole = acc.Devise_Symbole;
			this.Name = acc.Name;
			this.operations = new List<Operation>();
			this.operations.AddRange(Operations);
			
			this.Owner = acc.Owner;
			
			
		}	
		
		// lister les opérations en base
		public void GetOperations()
		{			
			operations = core.ReadLastOperations(this.Id, 0);

		}
		
		// ajouter une opération
		
		// modifier une opération
		
		
		
		// supprimer une opération
		public void DeleteOperation(int OpId)
		{
			if (OpId <= 0)
			{
				MessageBox.Show("Id opération incorrect");
			}
			else{
				string sql = "DELETE FROM OPERATION " +
					"WHERE Id = " + OpId.ToString();
				//acc.core.sf.NonSelectQuery(sql);
			}
		}
		
		// pointer une opération
		
		
		/// <summary>
		/// modifier le compte 
		/// </summary>
		/// <param name="acc"></param>
		public void UpdateAccount(){
			core.UpdateAccount(this);
		}
			
		
		/// <summary>
		///  Clone du comopte en cours
		/// </summary>
		/// <returns></returns>
		public Account Clone()
		{
			return Clone(this, true);
		}
		
		/// <summary>
		/// Clone du compte en paramètre
		/// </summary>
		/// <param name="acc"></param>
		/// <param name="WithCore"></param>
		/// <returns></returns>
		public Account Clone(Account acc, bool WithCore)
		{
			Account newacc = new Account();
			
			if (WithCore)
			{
				newacc.core = acc.core;
			}
			
			newacc.Id = acc.Id;
			newacc.Bank = acc.Bank;
			newacc.Bank_Id = acc.Bank_Id;
			newacc.BalanceProjected = acc.BalanceProjected;
			newacc.BalanceReal = acc.BalanceReal;
			newacc.Devise_Code = acc.Devise_Code;
			newacc.Devise_Label = acc.Devise_Label;
			newacc.Devise_Symbole = acc.Devise_Symbole;
			newacc.Name = acc.Name;
			newacc.operations = new List<Operation>();
			newacc.operations.AddRange(acc.Operations);
			
			newacc.Owner = acc.Owner;
			
			return newacc;
		}
		
	}
}
